// 初始化及更新通用
export default class EchartInit {
    constructor(config) {
        this.$echart = null;
        this.$resizeTimer = null;
        this.$clickTimer = null;
        this.$config = config;
        this.initEchartExample();
        this.hooks();
    }
    // 初始化图表实例
    initEchartExample() {
        this.$echart = Vue.$echarts.init(this.$config.el, 'macarons');
        this.registerMap();
    }
    // 注册地图
    async registerMap() {
        let { data } = await axios.get("/static/china.json", {
            noApped: true,
        });
        Vue.$echarts.registerMap("china", data);
    }
    // 操作事件
    hooks() {
        let { click, dbClick, mouseover } = this.$config.eventHooks;
        this.$echart.on("click", (e) => {
            clearTimeout(this.$clickTimer);
            this.$clickTimer = setTimeout(() => {
                click && click(e)
            }, 200)
        });
        this.$echart.on("dblclick", (e) => {
            clearTimeout(this.$clickTimer);
            dbClick && dbClick(e)
        });
        this.$echart.on("mouseover", (e) => {
            mouseover && mouseover(e)
        });
        if (window) {
            window.addEventListener('resize', () => {
                this.clientChangeSize();
            })
        }
    }
    // 初始化加载
    initLoadOptions(options) {
        console.log(options);
        this.$options = options;
        this.echartDataLoad();
    }
    // 加载图标配置数据
    echartDataLoad() {
        this.$echart.clear();
        this.$echart.setOption(this.$options, true);
    }
    // 屏幕发生改变时修改图表尺寸
    clientChangeSize() {
        if (!this.$echart) return;
        if (this.$resizeTimer) {
            clearTimeout(this.$resizeTimer);
        }
        this.$resizeTimer = setTimeout(() => {
            this.$echart.resize();
        }, 200);
    }
    // 清除屏幕发生改变时修改图表尺寸
    clearClientChangeSize() {
        if (!this.$echart) return;
        this.$echart.resize();
    }
}